/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"25CF2A3D-7084-48D5-A8B4-C91A91600466",variableType:4}
 */
var mue_subcap = null;

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"14336FCF-966F-4E38-B85B-4281E4A6EC88"}
 */
function onDataChange_codigo(oldValue, newValue, event) {
	if (controller.getSelectedIndex() == 1 && globals.gEstadoAbm == 1)
	{
		elements.descripcion.requestFocus()
		return true
	}
	else
	{
		elements.descripcion.requestFocus()
		codigo = oldValue
		return true
	}
}

/**
 * @properties={typeid:24,uuid:"285C6F07-CEC7-489E-806A-20521037E33F"}
 * @AllowToRunInFind
 */
function validar() {
	controller.setSelectedIndex(1)
	if (globals.gEstadoAbm == 1)
	{
		var $sql = 'SELECT rubro_id FROM rubro WHERE empresa = ? AND capitulo = ? AND subcapitulo = ? AND codigo = ?'
		var $args = [empresa, capitulo, subcapitulo, codigo]
		var $ds = databaseManager.getDataSetByQuery('contable',$sql,$args,-1)
		if ($ds.getMaxRowIndex() != 0) 
		{		
			return [false,false,"El código ingresado ya existe"]
		}
	}
	return [true]
}

/**
 * @properties={typeid:24,uuid:"11AAB37D-23A3-423C-A194-B33424EA69E3"}
 */
function imprimir()
{
	//forms.rubros_impresion.controller.showPrintPreview()
	jasper('impresion')
}

/**
 * @properties={typeid:24,uuid:"765E941C-2F96-4E25-9076-2CED6B60E58E"}
 */
function pdf()
{
	//globals.metodoPdf('rubros_impresion','Rubros - ' + globals.glegajo,true)
	jasper('pdf')
}

/**
 * @properties={typeid:24,uuid:"AC303436-E680-4F7D-A892-221976C8A786"}
 */
function xls()
{
	jasper('xls')
}

/**
 * @properties={typeid:24,uuid:"9F308634-945D-4CDF-80BF-CD7557FF5010"}
 */
function csv()
{
	jasper('csv')
}

/**
 * @param {String} tipo
 *
 * @properties={typeid:24,uuid:"CFAEACB4-8679-4C09-9883-8523FD9E1FFA"}
 */
function jasper(tipo)
{
	var $params = {
		userv: usuarios_to_uservs.razon_social
	}
	var $cols = ['rubro_to_capitulo.nombre','rubro_to_subcapitulo.descripcion','codigo','descripcion']
	var $ds	= databaseManager.convertToDataSet(foundset,$cols)
	$ds.setColumnName(1,'capitulo')
	$ds.setColumnName(2,'subcapitulo')
	globals.metodoJasper(tipo,'contable/rubros.jasper','Rubros',$ds,$params)
}